home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / fs154105.lha / FS1541 / main.c < prev    next >
C/C++ Source or Header  |  1996-11-24  |  4KB  |  201 lines

  1. /*
  2.     FS1541
  3.  
  4.     main.c
  5.  
  6.     The handler entry point.
  7.  
  8. */
  9.  
  10. #include <string.h>
  11.  
  12. #include <exec/types.h>
  13. #include <exec/execbase.h>
  14. #include <dos/dosextens.h>
  15. #include <dos/dostags.h>
  16. #include <dos/filehandler.h>
  17. #include <utility/utility.h>
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21.  
  22. #include "main.h"
  23. #include "packet.h"
  24. #include "disk.h"
  25. #include "volume.h"
  26. #include "support.h"
  27.  
  28. char verstring[] = "$VER: 1541-handler 0.5 (24.11.96)";
  29.  
  30. struct ExecBase *SysBase;
  31. struct DosLibrary *DOSBase;
  32. struct UtilityBase *UtilityBase;
  33.  
  34. struct Task *ourtask;
  35. struct MsgPort *ourport;
  36.  
  37. struct FileSysStartupMsg *fssm;
  38.  
  39. static BOOL MakeFSSM(BSTR);
  40.  
  41. /*-------------------------------------------------------------------------*/
  42.  
  43. void entry(void)
  44. {
  45.     struct DosPacket *startuppacket;
  46.     struct DosList *devnode;
  47.     LONG error = ERROR_NO_FREE_STORE;
  48.  
  49.     SysBase = *(volatile APTR*)4;
  50.  
  51.     ourtask = FindTask(NULL);
  52.  
  53.     ourport = &((struct Process *)ourtask)->pr_MsgPort;
  54.     WaitPort(ourport);
  55.     startuppacket = GetPacket(ourport);
  56.  
  57.     devnode = (struct DosList*)BADDR(startuppacket->dp_Arg3);
  58.  
  59.     if((DOSBase = (struct DosLibrary*)OpenLibrary(DOSNAME, 37)))
  60.     {
  61.         if((UtilityBase = (struct UtilityBase*)OpenLibrary("utility.library",37)))
  62.         {
  63.             if(MakeFSSM(startuppacket->dp_Arg2))
  64.             {
  65.                 devnode->dol_misc.dol_handler.dol_Startup = (BPTR)CTOB(fssm);
  66.  
  67.                 if(!(error = InitDiskSS(&((STRPTR)BTOC(fssm->fssm_Device))[1],fssm->fssm_Unit,fssm->fssm_Flags)))
  68.                 {
  69.                     if(!(error = InitVolumeSS()))
  70.                     {
  71.                         ULONG pktsig = 1<<(ourport->mp_SigBit);
  72.                         ULONG diskchgsig = 1<<diskchgintbit;
  73.                         ULONG mask = pktsig|diskchgsig;
  74.         
  75.                         error = 0;
  76.                         devnode->dol_Task = ourport;
  77.                         ReturnPacket(startuppacket, DOSTRUE, 0);
  78.         
  79.                         DoDiskInsert();
  80.             
  81.                         for(;;)
  82.                         {
  83.                             ULONG sigs;
  84.                     
  85.                             while(!( SetSignal(0,0)&mask || LoadDisk() ));
  86.         
  87.                             sigs = Wait(mask);
  88.                     
  89.                             if(sigs & pktsig)
  90.                                 DoPackets();
  91.                             if(sigs & diskchgsig)
  92.                             {
  93.                                 if(!inhibited)
  94.                                 {
  95.                                     /* We do the remove for security reasons */
  96.                                     DoDiskRemove();
  97.                                     DoDiskInsert();
  98.                                 }
  99.                             }
  100.                         }
  101.             
  102.                         QuitVolumeSS();
  103.                     }
  104.                     QuitDiskSS();
  105.                 }
  106.             } else error = ERROR_REQUIRED_ARG_MISSING;
  107.             CloseLibrary((struct Library*)UtilityBase);
  108.         }
  109.         CloseLibrary((struct Library*)DOSBase);
  110.     }
  111.  
  112.     if(error)
  113.         ReturnPacket(startuppacket, DOSFALSE, error);
  114. }
  115.  
  116. static BOOL MakeFSSM(BSTR startup)
  117. {
  118.     UBYTE str[258];
  119.     STRPTR src = BTOC(startup);
  120.     struct RDArgs *rdargs;
  121.  
  122.     if(src)
  123.     {
  124.         int i,len = src[0];
  125.  
  126.         /* Convert startup string */
  127.         CopyMem(&src[1], str, len);
  128.         str[len] = '\n';
  129.         str[len+1] = '\0';
  130.  
  131.         for(i=0;i<len;i++)
  132.             if(str[i] == '"') str[i] = ' ';
  133.  
  134.         if((rdargs = (struct RDArgs*)AllocDosObject(DOS_RDARGS, NULL)))
  135.         {
  136.             static char template[]=
  137.                 "D=DEVICE/A,"
  138.                 "U=UNIT/N/A,"
  139.                 "F=FLAGS/N,"
  140.                 "NS=NOAUTOSCAN/S"
  141.                 "I=INTERLEAVE/N";
  142.  
  143.             ULONG argarray[5];
  144.  
  145.             rdargs->RDA_Flags |= RDAF_NOPROMPT;
  146.             rdargs->RDA_Source.CS_Buffer = str;
  147.             rdargs->RDA_Source.CS_Length = strlen(str);
  148.             rdargs->RDA_Source.CS_CurChr = 0;
  149.  
  150.             if(ReadArgs(template, &argarray[0], rdargs))
  151.             {
  152.                 if((fssm = AllocVec(sizeof(struct FileSysStartupMsg), MEMF_PUBLIC)))
  153.                 {
  154.                     struct DosEnvec *env;
  155.                     STRPTR name;
  156.  
  157.                     if((env = AllocVec(sizeof(struct DosEnvec), MEMF_PUBLIC|MEMF_CLEAR)))
  158.                     {
  159.                         if((name = AllocVec(strlen((STRPTR)argarray[0])+2, MEMF_PUBLIC)))
  160.                         {
  161.                             strcpy(name+1, (STRPTR)argarray[0]);
  162.                             name[0] = strlen(name+1);
  163.  
  164.                             fssm->fssm_Unit = *(ULONG*)argarray[1];
  165.                             fssm->fssm_Device = (BPTR)CTOB(name);
  166.                             fssm->fssm_Flags = argarray[2] ? *(ULONG*)argarray[2] : 16;
  167.                             fssm->fssm_Environ = (BPTR)CTOB(env);
  168.  
  169.                             env->de_TableSize = 19;
  170.                             env->de_SizeBlock = 256/4;
  171.                             env->de_Surfaces = 1;
  172.                             env->de_SectorPerBlock = 1;
  173.                             env->de_BlocksPerTrack = 1;
  174.                             env->de_LowCyl = 0;
  175.                             env->de_HighCyl = 682;
  176.                             env->de_DosType = ID_DOS_DISK;
  177.  
  178.                             if(argarray[3])
  179.                                 autoscan = FALSE;
  180.  
  181.                             if(argarray[5])
  182.                                 interleave = *(ULONG*)argarray[5];
  183.  
  184.                             return(TRUE);
  185.                         }
  186.  
  187.                         FreeVec(fssm);
  188.                     }
  189.                     FreeVec(fssm);
  190.                 }
  191.  
  192.                 FreeArgs(rdargs);
  193.             }
  194.  
  195.             FreeDosObject(DOS_RDARGS, rdargs);
  196.         }
  197.     }
  198.  
  199.     return(FALSE);
  200. }
  201.